<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="../练习/vue.min.js"></script>
</head>

<body>
  <div id="app">
    <button @click="againClick">button</button>
  </div>

  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        timer: null
      },
      methods: {
        againClick() {
          this.debounce(this.btnClick, 1000)
        },
        btnClick() {
          return new Promise((res, rej) => {
            res('ok')
            rej('err')
          }).then(res => {
            console.log(res)
          })
        },
        debounce(fn, delay) {
          clearTimeout(this.timer)
          const that = this
          this.timer = setTimeout(() => {
            fn.apply(that)
          }, delay);
        }
      }
    });
  </script>
</body>

</html>